<template>
  <el-form :inline="true" :model="params" label-width="auto" class="demo-form-inline">
    <el-form-item :label="item.label" v-for="item in searchObj">
      <component
        v-if="item.type !== 'slot'"
        :is="item.com"
        v-model="params[item.key]"
      >
        <template #default v-if="item.type === 'select'">
          <el-option
            v-for="op in item.options"
            :key="op.key"
            :label="op.value"
            :value="op.value"
          />
        </template>
      </component>
      <template v-else>
        <slot :name="item.slot" :obj="item" :params="params"> </slot>
      </template>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="select">筛选</el-button>
      <el-button @click="reset">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { reactive, defineEmits } from "vue";
import { SearchObjType } from "../type/search";

let props = defineProps({
  searchObj: Array<SearchObjType>,
});
let emits = defineEmits(["changeReset", "changeSelect"]);
let params = reactive({});
const reset = () => {
  emits("changeReset");
};
const select = () => {
  emits("changeSelect");
};
</script>

<style lang="less" scoped></style>
